package city.spring.modules.medicalstation.medical.service.impl;

import city.spring.modules.medicalstation.medical.entity.MedicalRecordEntity;
import city.spring.modules.medicalstation.medical.repository.MedicalRecordRepository;
import city.spring.modules.medicalstation.medical.service.MedicalRecordService;
import city.spring.modules.medicalstation.medical.vo.MedicalRecordEntityVO;
import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.cache.annotation.CacheConfig;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * Service：
 *
 * @author
 * @date 2020-06-17 14:23:13
 */
@CacheConfig(cacheNames = {MedicalRecordServiceImpl.CACHE_NAME})
@Transactional(rollbackFor = Throwable.class)
@Service
public class MedicalRecordServiceImpl extends ServiceImpl<MedicalRecordRepository, MedicalRecordEntity> implements MedicalRecordService {

    @Override
    public void saveHealthSeeDoctor(MedicalRecordEntity entity) {
        if (!save(entity)) {
            throw new RuntimeException("保存信息失败");
        }
    }

    @Override
    public void updateHealthSeeDoctor(MedicalRecordEntity entity) {
        // 使用 updateById(entity); 修改数据时，将会修改 entity 对象中所有非null数据，如果某个字段为null，将会忽略该字段的修改
        boolean update = updateById(entity);
        if (!update) {
            throw new RuntimeException("修改信息失败");
        }
    }

    @Override
    public void deleteHealthSeeDoctor(String primaryKey) {
        removeById(primaryKey);
    }

    @Override
    public void deleteHealthSeeDoctor(List<String> primaryKeys) {
        removeByIds(primaryKeys);
    }

    @Override
    public IPage<MedicalRecordEntityVO> listPage(Page<? extends MedicalRecordEntity> page, Wrapper<? extends MedicalRecordEntity> wrapper) {
        return baseMapper.listPage(page, wrapper);
    }
}